<template>
  <div>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn='false'
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" @click="addHandle">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      :visible.sync="visible"
      :title="dialogTitle"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <testDriveModal :type="handleType" :rowData="formData" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import {
  searchTestDriveCars,
  editQueryTestDriveCars,
  addTestDriveCars,
  editTestDriveCars,
  searchVINList
 } from '@/api/potenCus/basedata/searchTestDriveCars';
import { dictionary } from '@/utils/dictMixin';
import testDriveModal from './testDriveModal';
export default {
  name: 'searchTestDriveCars',
  mixins: [dictionary],
  components: {
    testDriveModal
  },
  data() {
    return {
      fetchParams: {},
      visible: false,
      dialogTitle: '',
      fetchApi: searchTestDriveCars,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      conf:{ add: '新增', edit: '编辑', show: '显示' }
    };
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '试驾车系',
          dataIndex: 'intentSeries',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '试驾车辆',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '配置',
          dataIndex: 'configName',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '车牌号',
          dataIndex: 'vehicleMark',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '总里程(KM)',
          dataIndex: 'allMilliage',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '是否有效',
          dataIndex: 'isValid',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.isValid, '1004')}</span>;
          }
        },
        {
          title: '排序',
          dataIndex: 'rank',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      console.log('编辑',row)
      this.handleType = 'edit';
      this.formData = row;
      this.showHandler();
    },
    detailHandle(row) {
      this.handleType = 'show';
      this.formData = row;
      console.log(row)
      this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `试驾车${this.conf[this.handleType]}`;
      this.visible = true;
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }

  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
  }
};
</script>

<style lang="less" scoped>
</style>
